# TODO: Add comment
# 
# Author: Chuc Man The Great
###############################################################################

library(raster)
inputPath = "/home/phamha/Desktop/MetTiff"
listFile = list.files(path = inputPath,pattern=".tif$",full.names = TRUE,recursive=TRUE)
Size = length(listFile)

for(i in 1:Size){
	ras_file = listFile[i]
	pm = raster(ras_file)
	totalCell=length(pm)
	
	# delete all the negative values
	pm_value = values(pm)
	pm_value[pm_value==-9999]<-NA
	
	universalPMRaster=pm
	universalPMRaster[1:totalCell] = pm_value
	
	writeRaster(universalPMRaster,filename=ras_file,format="GTiff",overwrite=TRUE)
}

print("done")